sr=44100
kr=4410
nchnls=2


    instr 1 
  kmask     linuxjoystick   0, 1
;;; this uses the first two axes on your joystick.
  kaxes     tab       0, 1
  kb0       tab       kaxes+2, 1
  kx        tab       2, 1
  ky        tab       3, 1
  kx2       tab       4, 1
  ky2       tab       5, 1
  kb6       tab       kaxes+7, 1
  k_r, ktheta  cart2polar   kx, ky
  k_rdiff, kangdiff   rotation                    kx, ky
  k_r2, ktheta2       cart2polar                  kx2, ky2

  isz       tableng   2
  ifactor   = isz/(2*$M_PI) ; so phase / rotation line up
  idurfactor   =      isz/(sr*4)

  kpos      init      0
  kpos      =  kpos - kangdiff*ifactor
  kwrappos  wrap      kpos/isz, 0, 1

  aph       interp    kpos
  aph       butlp     aph, 0.25
  aphase    wrap      aph, 0, isz-1

  kamp      =  ampdb((32768-k_r)/-372.5)
  kamp      limit     kamp, 0, 2

  kcond     =  (kmask & (1<<(kaxes+7)))*kb6
  kdur      limit     k_r2, 1000, 30000
  kdur      =  kdur / 30000
  kdur      =  kdur * kdur * kdur
  kdur      =  kdur * idurfactor
            printf    "cond: %f dur: %f start: %f\\n", kcond, kcond, kdur, ktheta2*ifactor
            schedkwhen  kcond, 0.1, 1, 2, 0, kdur, (ktheta2+$M_PI)*ifactor

  aout      tab       aphase, 2
            outs      aout*kamp, aout*kamp
;done:
    endin

    instr 2
  aphasein  line      p4, p3, p4+p3*sr
  ain       inch      0
            tablew    ain, aphasein, 2
    endin

